package com.demo.webapp.kcfinder.config;

import java.util.ArrayList;
import java.util.List;

/**
 * 默认配置对象
 * 
 * @author ryuu.kk
 * 
 */
public class DefaultConfiguration implements Configuration {

	/**
	 * 版本序列化ID
	 */
	private static final long serialVersionUID = -4903408653043073091L;

	/**
	 * 默认配置参数
	 */
    public static final String DEFAULT_SETTINGS_PATH = "classpath:com/demo/webapp/kcfinder/config/default.properties";
    
	//protected Map<String, ActionConfig> actionConfigMap;
	
	protected List<PackageConfig> packageConfigList;
	
	public DefaultConfiguration() {
		//仅为CGLib提供调用
		packageConfigList = new ArrayList<PackageConfig>();
	}

	protected String getKey(String actionName, String method) {
		String key = "action:" + actionName + "." + method;
		return key;
	}

	@Override
	public ResultTypeConfig getResultType(ResultConfig config) {
		for (PackageConfig pc : packageConfigList) {
			ResultTypeConfig type = pc.getResultType(config.getResult());
			if (type != null) {
				return type;
			}
		}
		//设置默认类型? oh...
		return null;
	}

	@Override
	public void addPackageConfig(PackageConfig config) {
		packageConfigList.add(config);
	}

	@Override
	public PackageConfig getPackageConfig(String namespace) {
		for (PackageConfig config : packageConfigList) {
			if (config.getNamespace().equals(namespace)) {
				return config;
			}
		}
		return null;
	}
}
